let cinema_yh_controller = {
    // 查询所有的影院信息并分页展示
    findCinemaAll: function (pageNum, pageSize) {
        axios({
            url: "/admin/cinema/all/page",
            method: "POST",
            data: {
                pageNum: pageNum,
                pageSize: pageSize,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.cinemaList = value.data.data.list;
                vueapp.page = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的影片信息
    findMovieAll: function () {
        axios({
            url: "/admin/movie/all",
            method: "GET",
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.movieList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的影院品牌
    findCinemaBrandAll: function () {
        axios({
            url: "/admin/cinema/brand/all",
            method: "GET",
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.brandList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 根据ID精确查找影片的详细信息
    findCinemaDetailById: function (cinemaId) {
        axios({
            url: "/admin/cinema/detail/id",
            method: "GET",
            params: {
                cinemaId: cinemaId,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                var cinema = value.data.data.cinema;
                var movies = value.data.data.movies;
                var advantages = value.data.data.advantages;
                if (cinema != null) {
                    vueapp.cinemaDetail.cinema = cinema;
                }
                if (movies != null) {
                    vueapp.cinemaDetail.movies = movies;
                }
                if (advantages != null) {
                    vueapp.cinemaDetail.advantages = advantages;
                }
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 删除影院上映的影片
    deleteMovieOnCinemaDetail: function (movieId,cinemaId) {
        var movieList = this.cinemaDetail.movies;
        axios({
            url: "/admin/cinema/del/movie/on/cinema",
            method: "POST",
            data: {
                movieId: movieId,
                cinemaId: cinemaId,
                movies: movieList,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.cinemaDetail.movies = value.data.data;
            } else if (value.data.code == 3008) {
                vueapp.$alert("影片已经创建了放映计划，不允许被移除！", '提示', {
                    confirmButtonText: '确定',
                });
            } else {
                vueapp.$alert("发生了未知错误！", '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 新增上映影片
    addMovieOnCinemaDetail: function () {
        var movieList = this.cinemaDetail.movies;
        var newMovieIdList = this.cinemaDetail.newMovieList;
        axios({
            url: "/admin/cinema/add/movie/on/cinema",
            method: "POST",
            data: {
                movies: movieList,
                newMovieIdList: newMovieIdList,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                var number = value.data.data.length-movieList.length;
                vueapp.$message({
                    message: '成功添加'+number+'条记录',
                    type: 'success'
                });
                vueapp.cinemaDetail.movies = value.data.data;
            } else if (value.data.code == 2000) {
                vueapp.$alert("添加的影片在上映列表中全部都已经存在", '提示', {
                    confirmButtonText: '确定',
                });
            } else {
                vueapp.$alert("发生了未知错误！", '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 添加影院信息
    addCinema: function () {
        var cinemaName = this.cinema.cinemaName;
        var brandId = this.cinema.brandId;
        var cinemaAddress = this.cinema.cinemaAddress;
        var cinemaHotline = this.cinema.cinemaHotline;
        var startPurchasePrice = this.cinema.startPurchasePrice;
        var movieList = this.cinemaDetail.movies;
        axios({
            url: "/admin/cinema/add",
            method: "POST",
            data: {
                cinemaName: cinemaName,
                cinemaAddress: cinemaAddress,
                cinemaHotline: cinemaHotline,
                startPurchasePrice: startPurchasePrice,
                brandId: brandId,
                movies: movieList,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '保存成功',
                    type: 'success'
                });
                vueapp.changeOperateCard("index");
            } else {
                vueapp.$alert("发生了未知错误导致修改失败！", '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 修改影院信息
    updateCinema: function () {
        var cinemaName = this.cinemaDetail.cinema.cinemaName;
        var brandId = this.cinemaDetail.cinema.brandId;
        var cinemaAddress = this.cinemaDetail.cinema.cinemaAddress;
        var cinemaHotline = this.cinemaDetail.cinema.cinemaHotline;
        var startPurchasePrice = this.cinemaDetail.cinema.startPurchasePrice;
        var movieList = this.cinemaDetail.movies;
        var cinemaId = this.cinemaDetail.cinema.cinemaId;
        axios({
            url: "/admin/cinema/update",
            method: "POST",
            data: {
                cinemaId: cinemaId,
                cinemaName: cinemaName,
                cinemaAddress: cinemaAddress,
                cinemaHotline: cinemaHotline,
                startPurchasePrice: startPurchasePrice,
                brandId: brandId,
                movies: movieList,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '修改保存成功',
                    type: 'success'
                });
                vueapp.changeOperateCard("index");
            } else {
                vueapp.$alert("发生了未知错误导致修改失败！", '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },
}